<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.xml.stream.*" %>

<%!
Status status = new Status();

public class Status
{
	public String profileImage = null;
	public String screenName = null;
	public String text = null;
	public String createdDate = null;
	
	/*
	public Status(String profileImage, String screenName, String text, String createdDate)
	{
		this.profileImage = profileImage;
		this.screenName = screenName;
		this.text = text;
		this.createdDate = createdDate;
	}
	*/
}

public Status getStatus(XMLStreamReader parser) throws XMLStreamException
{
	while (parser.hasNext())
	{
		int event = parser.next();
		if (event == XMLStreamConstants.START_ELEMENT)
		{
			if (parser.getLocalName().equals("profile_image_url"))
			{
				parser.next();
				if (parser.isCharacters())
				{
					status.profileImage = parser.getText();
					status.profileImage = status.profileImage.replace("24x24", "48x48");
				}
			}
			else if (parser.getLocalName().equals("screen_name"))
			{
				parser.next();
				if (parser.isCharacters())
				{
					status.screenName = parser.getText();
				}
			}
			else if (parser.getLocalName().equals("text"))
			{
				parser.next();
				if (parser.isCharacters())
				{
					status.text = parser.getText();
				}
			}
			else if (parser.getLocalName().equals("created_at"))
			{
				parser.next();
				if (parser.isCharacters())
				{
					status.createdDate = parser.getText();
				}
			}
		}
		else if (event == XMLStreamConstants.END_ELEMENT && parser.getLocalName().equals("status"))
		{
			break;
		}
	}
	
	return status;
}
%>

<%
response.setCharacterEncoding("UTF-8");
URL url = new URL("http://api.minicloud.com.cn/statuses/public_timeline.xml");
URLConnection conn = url.openConnection();
InputStream in = null;

try
{
	in = conn.getInputStream();
}
catch (Exception e)
{
	e.printStackTrace();
}

XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader parser = factory.createXMLStreamReader(in);
%>

<html>
	<head>
		<title>Digur, public</title>
	</head>
	
	<body>
		<!-- <h3>Digur, public</h3> -->
		
		<table border="0">
			<%
			while (parser.hasNext())
			{
				int event = parser.next();
				if (event == XMLStreamConstants.START_ELEMENT && parser.getLocalName().equals("status"))
				{
					Status status = getStatus(parser);
					%>
					<tr>
						<td><img src="<%= status.profileImage %>" alt_txt="<%= status.profileImage %>" /></td>
						<td><%= status.screenName %></td>
						<td><%= status.text %></td>
						<td><%= status.createdDate %></td>
					</tr>
					<%
				}
				else if (event == XMLStreamConstants.END_DOCUMENT)
				{
					in.close();
				}
			}
			%>
		</table>
	</body>
</html>